﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CCWin;

namespace DC.Views
{
    public partial class Form_SelectPatient : Skin_DevExpress
    {
        public Form_SelectPatient()
        {
            InitializeComponent();
        }

        Utils.Database DB = Utils.Global.GlobalDB;
        public string patientID = "0"; // 为0时就表示没有选择

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            searchPatient();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            searchPatient();
        }
        private void searchPatient()
        {
            string sql = "select Patient_ID,Patient_name,Patient_phone from Patient where 1=1 ";
            if (textBox1.Text != string.Empty)
            {
                sql += "and Patient_name like'%" + textBox1.Text + "%'";
            }
            if (textBox2.Text != string.Empty)
            {
                sql += "and Patient_phone like'%" + textBox2.Text + "%'";
            }
            //MessageBox.Show(sql);
            DataSet patientSet = DB.GetDs(sql);
            this.patientList.BeginUpdate();
            patientList.Items.Clear();
            for (int i = 0; i < patientSet.Tables[0].DefaultView.Count; i++)
            {
                DataRow row = patientSet.Tables[0].DefaultView[i].Row;
                ListViewItem item = new ListViewItem(row["Patient_ID"].ToString());
                item.SubItems.Add(row["Patient_name"].ToString());
                item.SubItems.Add(row["Patient_phone"].ToString());
                this.patientList.Items.Add(item);
            }
            this.patientList.EndUpdate();
        }

        private void patientList_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (patientList.SelectedItems.Count == 0)
            {
                return;
            }
            else
            {
                this.patientID = patientList.SelectedItems[0].Text;
                Close();
            }
        }

        private void Form_SelectPatient_Load(object sender, EventArgs e)
        {
            searchPatient();
        }
    }
}
